<template>
	<view>
		<!-- <back></back> -->
		<view class="top">
			<view :style="'height:' + top +'px'"></view>
			<view class="u-flex u-row-between">
				<u-icon @click="back" name="arrow-left" size="45" color="#fff"></u-icon>
				<view class="u-flex top_sea">
					<image src="@/static/wImg/seach.png" class="top_sea_img"></image>
					<input type="text" @input="change" v-model="keyword"
						placeholder-style="color:#fff;" placeholder="搜索店铺商品">
				</view>
			</view>
		</view>
		<view class="classify u-flex u-row-between">
			<view class="cla_item u-flex" @click="claClick(index)" :class="index == claIndex ?'cla_css' : ''" v-for="item,index in claList">{{item}}
				<view class="san_wrap u-flex u-flex-col" v-if="index == 3">
					<image class="san_top" @click.stop="zheng" src="@/static/wImg/sanGrey.png"></image>
					<image class="san_bot" @click.stop="dao" src="@/static/wImg/sanGrey.png"></image>
				</view>
			</view>
		</view>
		<mescroll-body :sticky="true" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
			<u-waterfall v-if="sshow" style="padding: 25rpx 25rpx 0;" v-model="flowList" ref="uWaterfall">
				<template v-slot:left="{leftList}">
					<view class="demo-warter" @click="$func.jump('/wNew/pages/detail?id=' + item.id)"
						v-for="(item, index) in leftList" :key="index">
						<!-- 警告：微信小程序中需要hx2.8.11版本才支持在template中结合其他组件，比如下方的lazy-load组件 -->
						<u-lazy-load threshold="-450" border-radius="10" :image="item.image"
							:index="index"></u-lazy-load>
						<view style="margin-top: 20rpx;">
							{{item.title}}
						</view>
						
						<view class="demo-tag">
							<view class="demo-tag-text" v-for="(items,indexs) in item.json" :key="indexs">
								{{items}}
							</view>
							<!-- <view class="demo-tag-text demo-tag-text-grey">
								特产标签
							</view> -->
						</view>
						<view class="demo-price">
							<text>￥</text>{{item.price}}
							<text class="demo-price-grey">￥{{item.hx_price}}</text>
						</view>
						<view class="demo-shop" @click.stop="$func.jump('/wNew/pages/store?id=' + item.shop_id)">
							<!-- <image src="../../static/wImg/home.png"></image> -->
							<text class="mark" v-if="item.shop.isself == 1">平台</text>
							<text class="mark markOra" v-else>商家</text>
							<text class="mark markOra" v-if="item.platform_ms == 1">秒杀</text>
							<text class="mark markOra" v-if="item.platform_bk == 1">折扣</text>
							{{item.shop.shopname}}
							<u-icon name="arrow-right" color="#999"></u-icon>
						</view>
					</view>
				</template>
				<template v-slot:right="{rightList}">
					<view class="demo-warter" @click="$func.jump('/wNew/pages/detail?id=' + item.id)"
						v-for="(item, index) in rightList" :key="index">
						<u-lazy-load threshold="-450" border-radius="10" :image="item.image"
							:index="index"></u-lazy-load>
						<view style="margin-top: 20rpx;">
							{{item.title}}
						</view>
						<view class="demo-tag">
							<view class="demo-tag-text" v-for="(items,indexs) in item.json" :key="indexs">
								{{items}}
							</view>
							<!-- <view class="demo-tag-text demo-tag-text-grey">
								特产标签
							</view> -->
						</view>
						<view class="demo-price">
							<text>￥</text>{{item.price}}
							<text class="demo-price-grey">￥{{item.hx_price}}</text>
						</view>
						<view class="demo-shop" @click.stop="$func.jump('/wNew/pages/store?id=' + item.shop_id)">
							<!-- <image src="../../static/wImg/home.png"></image> -->
							<text class="mark" v-if="item.shop.isself == 1">平台</text>
							<text class="mark markOra" v-else>商家</text>
							<text class="mark markOra" v-if="item.platform_ms == 1">秒杀</text>
							<text class="mark markOra" v-if="item.platform_bk == 1">折扣</text>
							{{item.shop.shopname}}
							<u-icon name="arrow-right" color="#999"></u-icon>
						</view>
					</view>
				</template>
			</u-waterfall>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				top: 0,
				keyword: '',
				flowList: [],
				claList: ['综合', '销量', '新品', '价格'],
				claIndex: 0,
				sort:'weigh',
				order:'',
				sshow:true,
				goods_type:""
			}
		},
		onLoad(options) {
			let res = uni.getSystemInfoSync()
			if (res.safeAreaInsets.top == 0) {
				this.top = 20;
			} else {
				this.top = res.safeAreaInsets.top;
			}
			this.goods_type = options.goods_type
		},
		methods: {
			back() {
				uni.navigateBack()
			},
			claClick(index){
				this.claIndex = index
				if(index == 0){
					this.sort = 'weigh'
				}else if(index == 1){
					this.sort = 'sales' 
				}else if(index == 2){
					this.sort = 'createtime' 
				}else if(index == 3){
					this.sort = 'price' 
				}
				this.sshow = false
				this.mescroll.resetUpScroll();
			},
			zheng(){
				this.sort = 'price'
				this.claIndex = 3
				this.order = 'asc'
				this.sshow = false
				this.mescroll.resetUpScroll();
			},
			dao(){
				this.sort = 'price'
				this.claIndex = 3
				this.order = 'desc'
				this.sshow = false
				this.mescroll.resetUpScroll();
			},
			change(){
				this.sshow = false
				this.mescroll.resetUpScroll()
			},
			upCallback(page) {
				this.mescroll.optDown.use = false;
				this.mescroll.optUp.textNoMore = '- 已经到底啦 -'
				this.$u.post('/api/wanlshop/product/lists', {
					page: page.num,
					limit: page.size,
					search: this.keyword,
					sort: this.sort,
					order:this.order,
					filter: "{}",
					op: "{}",
					type: 'goods',
					goods_type:this.goods_type,
					location_city: uni.getStorageSync('city')
				}).then(res => {
					this.mescroll.endBySize(res.data.data.length, res.data.total);
					if (page.num == 1) this.flowList = []; //如果是第一页需手动制空列表
					this.flowList = this.flowList.concat(res.data.data); //追加新数据
					this.sshow = true
				}).catch(() => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.top {
		z-index: 9999;
		padding: 0 20rpx 20rpx;
		background-color: #606DCE;

		.top_add {

			.top_add_text {
				width: 120rpx;
				font-size: 28rpx;
				color: #FFF;
				overflow: hidden; // 文字超长隐藏
				text-overflow: ellipsis; // 显示...
				white-space: nowrap; // 单行显示
			}

			.top_san {
				width: 22rpx;
				height: 10rpx;
				margin-left: 10rpx;
			}
		}

		.top_sea {
			flex: 1;
			margin-left: 40rpx;
			height: 60rpx;
			padding: 0 18rpx;
			border-radius: 20rpx;
			background: rgba(255, 255, 255, 0.7);
			border-radius: 10rpx 10rpx 10rpx 10rpx;

			.top_sea_img {
				width: 25.15rpx;
				height: 23.6rpx;
			}

			input {
				color: #fff;
				height: 20rpx;
				font-size: 24rpx;
				padding: 0 18rpx;
				margin-left: 18rpx;
				border-left: 1rpx solid #fff;
			}
		}
	}


	.demo-warter {
		border-radius: 8px;
		margin: 5px;
		background-color: #ffffff;
		padding: 8px;
		position: relative;
	}

	.demo-image {
		width: 100%;
		border-radius: 4px;
	}

	.demo-title {
		// font-size: 30rpx;
		// margin-top: 5px;
		// color: $u-main-color;
	}

	.demo-tag {
		display: flex;
		margin-top: 5px;
	}

	.demo-tag-owner {
		background-color: $u-type-error;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		padding: 4rpx 14rpx;
		border-radius: 50rpx;
		font-size: 20rpx;
		line-height: 1;
	}

	.demo-tag-text {
		border: 1px solid #F43000;
		color: #F43000;
		margin-right: 8px;
		line-height: 1;
		padding: 8rpx 24rpx 8rpx 16rpx;
		display: flex;
		align-items: center;
		border-radius: 4rpx;
		font-size: 20rpx;
	}

	.demo-tag-text-grey {
		border: 1px solid #999;
		color: #999;
	}

	.mark {
		font-size: 20rpx;
		color: #fff;
		padding: 4rpx 10rpx;
		background: #606DCE;
		border-radius: 4rpx;
		margin-right: 12rpx;
	}
	.markOra{
		background: #ef5205;
	}

	.demo-price {
		font-size: 30rpx;
		color: $u-type-error;
		margin-top: 5px;
		font-weight: bold;
		font-size: 32rpx;

		text {
			font-size: 20rpx;
		}

		.demo-price-grey {
			color: #D3D3D3;
			font-size: 20rpx;
			font-weight: 400;
			margin-left: 18rpx;
			text-decoration: line-through;
		}
	}

	.demo-shop {
		font-size: 22rpx;
		color: $u-tips-color;
		margin-top: 5px;
		display: flex;
		flex-wrap: wrap;
		align-items: center;

		image {
			width: 20rpx;
			height: 20rpx;
			margin-right: 8rpx;
		}
	}

	.classify {
		height: 78rpx;
		padding: 0 60rpx;
		background: #FFFFFF;

		.cla_item {
			font-size: 28rpx;
			color: #333;
			z-index: 9999;
			
			.san_wrap{
				margin-left: 5rpx;
			}
			
			.san_top{
				width: 14rpx;
				height: 12rpx;
			}
			.san_bot{
				width: 14rpx;
				height: 12rpx;
				 transform: rotate(180deg);
			}
		}

		.cla_css {
			color: #606DCE;
		}
	}
</style>